Skip to content

Add comprehensive unit tests for contract, router, and problem modules#7

Merged
ConsoleTVs merged 4 commits into
mainfrom
test/add-unit-tests-contract-router-problem
Apr 12, 2026
Merged

Add comprehensive unit tests for contract, router, and problem modules#7
ConsoleTVs merged 4 commits into
mainfrom
test/add-unit-tests-contract-router-problem

Conversation

@ConsoleTVs
Copy link
Copy Markdown
Member

Summary

  • Add 154+ unit test functions across contract, router, and problem modules
  • Bring contract/request and contract/response from 0% to 100% statement coverage
  • Bring router from 60% to 100% coverage (removed unreachable dead code in registerPair)
  • Bring problem from 0% to 100% coverage and problem/internal from 86.8% to 100%

Contract Module (13 new test files)

  • Root package: sentinel error values and context key assertions
  • request/: body parsing (JSON, XML, bytes, limited variants), cookies, headers, params, query strings, hooks, sessions
  • response/: static responses (Raw, JSON, XML, HTML, templates, redirects, SafeRedirect), streaming (Stream, SSE, context cancellation, non-flushable writer)

Router Module (57 new tests + dead code removal)

  • All HTTP method shortcuts (Post, Put, Patch, Delete, Head, Connect, Options, Trace)
  • Middleware application and execution order
  • Group, Grouped, Clone, With sub-router behavior
  • Pattern registration: trailing slash, root, catch-all wildcard
  • Handler/HandlerMatch inspection, Record helper
  • Removed unreachable CutSuffix branch in registerPair (path.Join always strips trailing slashes)

Problem Module (68 new tests across 3 files)

  • problem_test.go: constructors, additional field CRUD, error wrapping, stack traces, JSON marshal/unmarshal, HTTP content negotiation, all three response handlers
  • utils_test.go: stackTrace with nil, simple, wrapped, and joined errors
  • internal/accept_test.go: Quality method, malformed media types, empty accept, wildcard matching

… helpers

Cover all functions in contract root (sentinel errors, context keys),
request/ (body, cookie, header, hooks, param, query, session), and
response/ (static, stream) subpackages achieving 100% statement
coverage on request and response packages.
Add 57 test functions covering all HTTP method shortcuts, middleware
execution order, group/clone/with sub-routers, pattern registration
(trailing slash, root, catch-all), Handler/HandlerMatch, and Record.
Remaining 3.3% is unreachable dead code in registerPair.
Add 55 tests for problem.go (constructors, additional CRUD, error
wrapping, stack traces, JSON marshal/unmarshal, content negotiation,
HTTP handlers), 6 tests for utils.go (stackTrace with nil, simple,
wrapped, and joined errors), and 7 tests for internal/accept.go
(Quality, malformed media, empty accept) bringing internal from
86.8% to 100%.
…rPair

path.Join in Method() always strips trailing slashes before patterns
reach registerPair, making the CutSuffix branch dead code. Removing
it brings router coverage from 96.7% to 100%.
@ConsoleTVs ConsoleTVs marked this pull request as ready for review April 11, 2026 17:17
@ConsoleTVs ConsoleTVs merged commit cd1a886 into main Apr 12, 2026
3 checks passed
@ConsoleTVs ConsoleTVs deleted the test/add-unit-tests-contract-router-problem branch April 12, 2026 09:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant